package com.geotmt.billingcenter.modules.hive.provider;

import org.apache.ibatis.annotations.Param;

/**
 * @Description Hive Sql
 * @Author      yanghanwei
 * @Mail        yanghanwei@geotmt.com
 * @Date        2019/4/10 10:54
 * @Version     v1
 **/
public class ConsumeHiveProvider {

    public String createTest (String tabelName){
        StringBuffer sql = new StringBuffer();
        sql.append("CREATE EXTERNAL TABLE IF NOT EXISTS " +tabelName+ " (" +
                "create_time string," +
                "id bigint," +
                "label string," +
                "msg string," +
                "source_data string," +
                "uuid string," +
                "ht_flag string" +
                ")" +
                "partitioned by (dt_flag string)" +
                "ROW FORMAT DELIMITED " +
                "FIELDS TERMINATED BY '\\001'" +
                "LINES TERMINATED BY '\\n'");
        return sql.toString();
    }

    /**
     * 查询Hive表中该日期消耗的List
     * @return
     */
    public String listForDay (String dayFlag){
        StringBuffer sql = new StringBuffer();
        sql.append("SELECT user_id cuserId,inner_if_type interfaceType, isp, count_get countGet,count_query countQuery,count_time_out countTimeout,count_charging countCharging,day_flag dayFlag" +
                " FROM fin_consume_statis WHERE day_flag=#{dayFlag}");
        return sql.toString();
    }

    /**
     * 查询hive中某段时间内的消耗List
     * @param startDay
     * @param endDay
     * @return
     */
    public String listForDate (@Param(value = "startDay") String startDay,
                               @Param(value = "endDay") String endDay){
        StringBuffer sql = new StringBuffer();
        sql.append("SELECT user_id cuserId,inner_if_type interfaceType,isp, count_get countGet,count_query countQuery,count_time_out countTimeout,day_flag dayFlag" +
                " FROM fin_consume_statis WHERE day_flag>=#{startDay} AND day_flag<=#{endDay}");
        return sql.toString();
    }

}
